﻿using NFine.Application.BusinessManage;
using NFine.Code;
using NFine.Domain.Entity.BusinessManage;
using System.Web;
using System.Web.Mvc;

namespace NFine.Web.Areas.BusinessManage.Controllers
{
    public class D_GoodsController : ControllerBase
    {
        private D_GoodsApp goodsApp = new D_GoodsApp();

        [HttpGet]
        [HandlerAjaxOnly]
        public ActionResult GetGridJson(Pagination pagination, string keyword)
        {
            var data = new
            {
                rows = goodsApp.GetList(pagination, keyword),
                total = pagination.total,
                page = pagination.page,
                records = pagination.records
            };
            return Content(data.ToJson());
        }
        [HttpGet]
        [HandlerAjaxOnly]
        public ActionResult GetGridJsonenable(Pagination pagination, string keyword)
        {
            var data = new
            {
                rows = goodsApp.GetListenable(pagination, keyword),
                total = pagination.total,
                page = pagination.page,
                records = pagination.records
            };
            return Content(data.ToJson());
        }

        [HttpGet]
        [HandlerAjaxOnly]
        public ActionResult GetGrid(string keyword)
        {
            var data = goodsApp.GetGrid(keyword);
            return Content(data.ToJson());
        }

        [HttpGet]
        [HandlerAjaxOnly]
        public ActionResult GetFormJson(string keyValue)
        {
            var data = goodsApp.GetForm(keyValue);
            return Content(data.ToJson());
        }
        //[HttpPost]
        //[HandlerAjaxOnly]
        public ActionResult FileUpload()
        {
            HttpPostedFileBase imgFile = Request.Files[0];
            //返回图片地址
            string newFilename = System.DateTime.Now.ToString("yyyyMMddHHmmss") + System.IO.Path.GetFileName(imgFile.FileName);

            imgFile.SaveAs(Server.MapPath("~/photo/" + newFilename));
            return Content("photo/" + newFilename);
        }

        [HttpPost]
        [HandlerAjaxOnly]
        public ActionResult SubmitForm(D_GoodsEntity areaEntity, string keyValue)
        {
            goodsApp.SubmitForm(areaEntity, keyValue);
            return Success("操作成功。");
        }
        [HttpPost]
        [HandlerAjaxOnly]
        [HandlerAuthorize]
        [ValidateAntiForgeryToken]
        public ActionResult DeleteForm(string keyValue)
        {
            goodsApp.DeleteForm(keyValue);
            return Success("删除成功。");
        }
    }
}
